<?php

class Rating extends DataMapper {
	
	var $table_name	= 'ratings';
    
    var $has_many = array(
			'user' => array(			
	            'class' => 'user',
	            'other_field' => 'rating',
	            'join_self_as' => 'rating',
	            'join_other_as' => 'user',
	            'join_table' => 'r_ratings_users'),
    		'gallery' => array(			
	            'class' => 'gallery',
	            'other_field' => 'rating',
	            'join_self_as' => 'rating',
	            'join_other_as' => 'gallery',
	            'join_table' => 'r_galleries_ratings'),
    );
    
    var $validation = array(
    	'reftype_rating' => array(
            'label' => 'Type rating',
            'rules' => array('required', 'trim', 'integer'),
		),
		'rated_item_id' => array(
            'label' => 'Rated Item ID',
            'rules' => array('required', 'trim', 'integer'),
		),
		'rating' => array(
            'label' => 'Rating value',
            'rules' => array('required', 'trim', 'valid_match' => array('1', '2', '3', '4', '5')),
		)
    );
    
    function _integer($field)
    {
    	return ( ! preg_match('/^([0-9])+$/i', $field)) ? FALSE : TRUE;
    }
}

/* End of file rating.php */
/* Location: ./application/models/rating.php */